home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / prodpack.zip / DB4PPSRC.EXE / _WHATPAR.PRG < prev    next >
Text File  |  1993-05-04  |  3KB  |  115 lines

  1. FUNCTION _WhatPara   && Comma Delimited String to Array
  2. PARAMETER pa_array, pc_string, pc_delim
  3. *--------------------------------------------------------------------
  4. * NAME
  5. *   _WhatPara - copy data into array from comma
  6. *              delimited string.
  7. *
  8. * SYNOPSIS
  9. *   _WhatPara( pa_array, pc_string )
  10. *
  11. * DESCRIPTION
  12. *   _WhatPara() will copy into an array pa_array the
  13. *   character values in the comma delimited string
  14. *   pc_string.  The array will be created if
  15. *   necessary, with as many elements as needed based
  16. *   on the comma delimited string.  The main intent of
  17. *   the _WhatPara() function is as a work-around for
  18. *   the seven parameter limit of dBASE IV UDF's.
  19. *
  20. *   _WhatPara() will return the number of array
  21. *   elements assigned.  Note that _WhatPara() will
  22. *   overwrite any existing array or variable with the
  23. *   same name as pa_array.
  24. *
  25. *   There is no explicit limit on the number of data
  26. *   elements that the string can contain.  (Consult
  27. *   the documentation for the maximum length of
  28. *   strings in your version of dBASE.)
  29. *
  30. * PARAMETERS
  31. *   pa_array  = name of array to use or create
  32. *   pc_string = comma delimited list of data elements
  33. *               to load into the array
  34. *   pc_delim  = optional delimiter, default is ",".  Only the
  35. *               first character is used if more than one
  36. *               is supplied.
  37. *
  38. * EXAMPLE
  39. *
  40. *   ln_howmany = _WhatPara("paralist","1,2,,foo bar,4")
  41. *
  42. *   The array:  PARALIST[1] = "1"
  43. *               PARALIST[2] = "2"
  44. *               PARALIST[3] = ""
  45. *               PARALIST[4] = "foo bar"
  46. *               PARALIST[5] = "4"
  47. *
  48. *   ln_howmany = 5
  49. *
  50. * LIMITATIONS
  51. *   If the final character of the data string is a
  52. *   comma, an error will occur.
  53. *
  54. * VERSION
  55. *   dBASE IV 1.1
  56. *
  57. * SEE ALSO:
  58. *   COPY TO ARRAY
  59. *
  60. *--------------------------------------------------------------------
  61.  
  62.   PRIVATE lc_args, lc_delimit, lc_lenlook, lc_nxt_tok, lc_posit, ;
  63.           lc_str, ln_count
  64.  
  65.   *-- Check for type of look4for string, terminate if not character
  66.   IF TYPE("pc_string") <> "C" .OR. TYPE("pa_array") <> "C"
  67.     RETURN(.F.)
  68.   ENDIF
  69.  
  70.   *-- Check for the existance of the array
  71.   IF TYPE("&pa_array[1]") <> "U"
  72.      RELEASE &pa_array
  73.   ENDIF
  74.  
  75.   *-- Determine number of arguments, and assign it to LC_ARGS
  76.   IF TYPE( "PC_DELIM" ) = "C"
  77.     lc_delimit = LEFT( pc_delim, 1 )
  78.   ELSE
  79.     lc_delimit = ","
  80.   ENDIF
  81.   lc_posit = 1
  82.   lc_lenlook = LEN(pc_string)
  83.   ln_count = 0
  84.  
  85.   DO WHILE lc_posit < lc_lenlook
  86.  
  87.      IF SUBSTR(pc_string, lc_posit, 1) = lc_delimit
  88.         ln_count = ln_count + 1
  89.      ENDIF
  90.  
  91.      lc_posit = lc_posit + 1
  92.   ENDDO
  93.  
  94.   lc_args = ln_count + 1
  95.   *-- Declare the return array pa_array
  96.   PUBLIC ARRAY &pa_array[lc_args]
  97.  
  98.   *-- Put the elements in place
  99.   lc_posit = 1
  100.   lc_str = pc_string
  101.   lc_nxt_tok = AT(lc_delimit,lc_str)
  102.  
  103.   DO WHILE lc_nxt_tok > 0
  104.      STORE LEFT(lc_str, lc_nxt_tok-1) TO &pa_array[lc_posit]
  105.      lc_str = SUBSTR(lc_str, lc_nxt_tok + 1 )
  106.      lc_nxt_tok = AT(lc_delimit,lc_str)
  107.      lc_posit = lc_posit + 1
  108.   ENDDO
  109.  
  110.   STORE LEFT(lc_str, LEN(lc_str)) TO &pa_array[lc_posit]
  111.  
  112. RETURN (lc_args)
  113. *-- EOF: _WhatPara( pa_array, pc_string )
  114.  
  115.